home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: automatic charrs
- Date: Sat, 24 Feb 96 16:28:50 GMT
- Organization: none
- Message-ID: <825179330snz@genesis.demon.co.uk>
- References: <4glp29$dsh@d2.tufts.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4glp29$dsh@d2.tufts.edu>
- rdorich@emerald.tufts.edu "Roberto Dorich" writes:
-
- >Hello,
- >
- >Could someone enlighten me, and tell me why the following program runs
- >just dandy using Sun's cc (3.0.1), but crashes using gcc (?) ?
- >
- >#include <stdio.h>
- >char *b() { return "Hello";}
- >
- >main() {
- > char *a=b();
- >
- > a[0]='X';
- > printf("--> %s\n",a);
- >}
-
- It is illegal to write to a string literal in C (it results in undefined
- behaviour. On your system gcc probably puts the string literal in a read-only
- segment whereas cc doesn't. Both approaches are valid forms of
- undefined behaviour). I'd favour gcc here - it helped to identify a bug
- in your program.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-